//
//  TagContribution.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/9/29.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "TagContribution.h"
#import "LewPopupViewController.h"
#import "AddMark.h"
#import "AddBlacklist.h"
#import "CustomizeView.h"
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface TagContribution ()<UITableViewDelegate,UITableViewDataSource,ABNewPersonViewControllerDelegate>
{
    NSMutableArray *nameArr;
    BOOL isShow;
}
- (IBAction)call:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *del;
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (strong, nonatomic) CustomizeView *customizeView;
@end

@implementation TagContribution

- (void)viewDidLoad {
    [super viewDidLoad];
    [super setTitleView:self.view withName:@"标记贡献"];
    nameArr =[NSMutableArray array];
    [nameArr addObject:@"添加标记／修改标记"];
    [nameArr addObject:@"加为联系人"];
    [nameArr addObject:@"加入黑名单"];
    _table.delegate =self;
    _table.dataSource =self;
    _customizeView =[CustomizeView headerView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (IBAction)call:(id)sender {
    //拨打电话
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return nameArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *TableSampleIdentifier = @"1";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:TableSampleIdentifier];
    }
    cell.textLabel.text = [nameArr objectAtIndex:indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        //添加标记
        AddMark *mark =[AddMark headerView];
        __weak  TagContribution *wself = self;
        mark.closeblock = ^(){
            NSLog(@"回调回来的");
            [wself lew_dismissPopupView];
            isShow =YES;
        };
        [self lew_presentPopupView:mark animation:[LewPopupViewAnimationDrop new] dismissed:^{
            if (isShow) {
                [wself lew_presentPopupView:wself.customizeView animation:[LewPopupViewAnimationDrop new] dismissed:^{
                }];
                isShow=NO;
            }
        }];
    }else if(indexPath.row==1){
            ABNewPersonViewController *p =[[ABNewPersonViewController alloc]init];
            p.newPersonViewDelegate =self;
            [self.navigationController pushViewController:p animated:YES];
    }else{
        //加入黑名单
        AddBlacklist *h = [AddBlacklist headerView];
        [self lew_presentPopupView:h animation:[LewPopupViewAnimationDrop new] dismissed:^{
            
        }];
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 49;
}
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(nullable ABRecordRef)person;{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    self.navigationController.navigationBarHidden =NO;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.navigationBarHidden =YES;
}
@end
